package xyz.xtt.asset.vo;

import java.util.Objects;
import java.util.Optional;

import com.alibaba.nacos.shaded.com.google.common.primitives.Longs;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import xyz.xtt.asset.api.enums.AssetTypeEnum;
import xyz.xtt.asset.entity.TblAsset;
import xyz.xtt.asset.entity.TblAssetExt;
import xyz.xtt.asset.entity.TblAssetStaticResource;

/**
 * @author huqibo
 * @date 2024/11/07
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class AssetSynMessageSaveItem {
	private TblAsset asset;
	private TblAssetExt assetExt;
	private TblAssetStaticResource assetStaticResource;

	/**
	 * 最后去重使用
	 */

	public String groupKey() {
		return asset.getGoodsId();
	}

	public String firstOwnerId() {
		return asset.getOwnerId();
	}

	public Long goodsId() {
		return Optional.ofNullable(asset).map(TblAsset::getGoodsId).map(Longs::tryParse).orElse(0L);
	}

	public SyncResponseMsg convert() {
		Integer firstType = asset.getFirstType();
		AssetTypeEnum queryConvert = AssetTypeEnum.queryConvert(firstType);
		if (Objects.isNull(queryConvert)) {
			return null;
		}
		return SyncResponseMsg.builder().typeCode(queryConvert.name()).ts(System.currentTimeMillis()).goodsId(asset.getGoodsId()).build();
	}
}
